﻿using System;
using System.Collections.Generic;
using System.Text;

namespace DataStandard.Tools
{
    public class DataTypeWithByteLength
    {
        /// <summary>
        /// 根据数据类型，返回Byte数据长度定义。
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        /// <exception cref="NotSupportedException"></exception>
        public static int GetByteLength(string type)
        {
            var length = 1;
            switch (type)
            {
                case "INT16":
                case "UINT16":
                    length = 2;
                    break;
                case "INT32":
                case "UINT32":
                case "FLOAT":
                    length = 4;
                    break;
                case "BOOL":
                    length = 1;
                    break;
                default:
                    throw new NotSupportedException("GetByteLength(string type) 未定义数据类型");
                    break;
            }

            return length;
        }

        
    }

    
}
